﻿module Program
open System
open BJK.Analysis
open ABSTRACT_INTERPRETER
let samplesDir = "C:\\SMLNJ\\svn\\MSc\\SamplePrograms\\"
CG.debug := false;

//let ast1 = BJKParse.aFile(samplesDir + "amir1.core");
//let ast2 = BJKParse.aFile(samplesDir + "amir2.core");
//let ast3 = BJKParse.aFile(samplesDir + "amir3.core");
//let ast31 = BJKParse.aFile(samplesDir + "amir3.1.core");
//let ast4 = BJKParse.aFile(samplesDir + "amir4.core");
//let ast5 = BJKParse.aFile(samplesDir + "sample1.core");
try
    let ast6 = BJKParse.aFile(samplesDir + "sample5.core");

    let ast = ast6;

    printfn "%s" 
      ("============================================\n" +
      "analysed program:\n" +
      (Core.prt ast) +
      "============================================\n"); 

    printfn "\nPress any key to start analysis..."                                                                                                                                                               
    let _ = Console.ReadKey()
    let absInt = AbstractInterpreter(BJK.Analysis.PolyParams())
    let g = absInt.analyse(ast)

    let edgeCount = ref 0
    for p in g.Keys do 
        for qd in g.[p] do
            edgeCount := !edgeCount + 1
    printfn "Finished!\nPress any key to continue..."                                                                                                                                                               
    let _ = Console.ReadKey()
    printfn "%s" 
          ("New abstract interpreter algorithm analysis result:\n" +
          CG.prtEdges(g) +
          "============================================\n");
  (*  printfn "%s" 
          ("Original BJK algorithm Poly analysis result:\n" + 
           CG.prtDfr(Pol.analyse(ast)) + 
           "\n============================================\n"); 
*)
    printfn "result graph contains %d edges.\nPress any key to exit..."  (!edgeCount)        
with 
    |Util.Fail s -> printfn "%s\n" ("Fatal error occured at " + s)
    |_ -> ()
let _ = Console.ReadKey()

